package com.zone.io;

import cn.hutool.core.io.IoUtil;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;

/**
 * @author: zongzi
 * @description: TODO
 * @date: 2023/12/4
 */
public class Resources {

    private static final ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();

    /**
     * 根据指定的资源路径获取Reader
     *
     * @param path
     * @return
     */
    public static Reader getReaderByResourcePath(String path) throws IOException{
        InputStream inputStream = systemClassLoader.getResourceAsStream(path);
        if (null != inputStream) {
            return IoUtil.getUtf8Reader(inputStream);
        }
        throw new IOException("could not found path " + path);
    }

    public static Class<?> classForName(String namespace) throws ClassNotFoundException {
        return Class.forName(namespace);
    }
}
